import {
  _decorator,
  Component,
  Node,
  resources,
  SpriteFrame,
  Texture2D,
  ImageAsset,
} from "cc";

export class Kit {
  private static instance: Kit = null;
  private static uniqueId = Symbol(",");

  public static getInstance(): Kit {
    if (!this.instance) {
      this.instance = new Kit();
      
      this[Kit.uniqueId] = Math.random().toString(36);
      console.log(this[Kit.uniqueId]);
    }
    return this.instance;
  }

  // 加载所有图片资源并返回Promise
  loadImages(
    imageFolderPath: string,
    type: typeof SpriteFrame = SpriteFrame
  ): Promise<SpriteFrame[]> {
    return new Promise<SpriteFrame[]>((resolve, reject) => {
      resources.loadDir(imageFolderPath, type, function (err, data) {
        if (err) {
          reject(err);
          return;
        }

        resolve(data);
      });
    });
  }

  img2Texture2SpriteFrame(imageAsset: ImageAsset) {
    // 创建 Texture2D 对象
    const texture = new Texture2D();
    texture.image = imageAsset;

    // 创建 SpriteFrame 并设置 Texture2D
    const spriteFrame = new SpriteFrame();
    spriteFrame.texture = texture;
  }
}
